<template>
  <div class="background">
    <div class="big-contain">
      <el-scrollbar class="scrollbar">
        <div class="survey">
          <h2>{{this.surveyInfo.title}}</h2>
          <p style="text-decoration: #666666">{{this.surveyInfo.introduction}}</p>
          <div style="border:1px solid #CCC;width: 80%"></div>
          <el-form  style="width: 60%" >
            <div class="item" v-for="(item, index) in this.questionArray" :key="index">
              <el-form-item :label="(index+1)+'、'" >
                <div class="item_title">
                  <span v-if="item.type==0">[单选]</span>
                  <span v-if="item.type==1">[文本]</span>
                  <span v-if="item.type==2">[多选]</span>
                  <span v-text="item.content"></span>
                  <span v-if="item.must == 1" style="text-decoration: red">*（必答）</span>
                </div>

                <!-- 单选 -->
                <div v-if="item.type == 0 ">
                  <el-radio-group  v-model="item.choiceContent[0]" style="display: flex;flex-direction: column">
                    <el-radio
                      :label="em.option"
                      :key="em.option"
                      v-for="em in item.optionContent" style="margin-left: 20px;margin-bottom: 15px"
                    >{{ em.option }}</el-radio>
                  </el-radio-group>
                </div>

                <!-- 多选 -->
                <div v-if="item.type == 2 ">
                  <el-checkbox-group  v-model="item.choiceContent" style="display: flex;flex-direction: column">
                    <el-checkbox
                      :label="em.option"
                      :key="em.option"
                      v-for="em in item.optionContent" style="margin-left: 20px">
                      {{em.option}}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>

                <!-- 矩阵填空 -->
                <div v-if="item.type == 1 ">
                  <div class="warp" >
                    <el-input  type="textarea" v-model="item.textAnswer" style="margin-left: 20px"></el-input>
                  </div>
                </div>
              </el-form-item>
            </div>
          </el-form>
        </div>
      </el-scrollbar>
    </div>
    <div class="buttonbar">
      <button class="bbutton" @click="goback"> 退出</button>
    </div>
  </div>
</template>

<script>
import {showAnswerSurvey} from "../../api/survey"
export default {
  name: "answererCheckanswer",
  data(){
    return {
      answerid:'',
      surveyInfo:{

      },
      questionArray:[
        {
          id:'1',
          content:'我是个什么样的人',
          type:0,
          must:1,
          textAnswer:'',
          choiceContent:['我是傻子'],
          optionContent:[
            {
              option:'我是傻子',
            },
            {
              option: '我是憨批',
            }
          ],
        },
        {
          id:'2',
          content:'学校怎么样',
          type:2,
          must:1,
          textAnswer:'',
          choiceContent:['我是傻子','我是憨批'],
          optionContent:[
            {
              option:'我是傻子',
            },
            {
              option:'我是好孩子',
            },
            {
              option: '我是憨批',
            }
          ],
        }
      ]
    }
  },
  methods:{
    goback(){
      this.$router.back()
    },
    firstin(){
      console.log(this.answerid)
      console.log(this.surveyInfo.id)
      showAnswerSurvey(this.answerid,this.surveyInfo.id).then((response)=>{
        console.log(response)
        if(response.data.code === 200){
          this.$message.success("查询成功")
          this.surveyInfo = response.data.data.surveyInfo
          this.questionArray = response.data.data.questionArray

          console.log(this.surveyInfo)
          console.log(this.questionArray)
        }else {
          this.$message.error("查询失败")
        }
      })
    }
  },
  created() {
    this.surveyInfo.id = this.$route.query.surveyId
    this.answerid = this.$route.query.answerId
    this.firstin()
  }
}
</script>

<style scoped>
.bbutton{
  width: 15%;
  height: 40px;
  border-radius: 24px;
  border: none;
  outline: none;
  background-color: rgb(81, 133, 206);
  color: #fff;
  font-size: 0.9em;
  cursor: pointer;
  margin-bottom: 7px;
  margin-top: 7px;
}
.bbutton:hover{
  box-shadow: 0px 3px 3px 0px rgb(36, 59, 97);
}
.scrollbar{
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}
.scrollbar /deep/ .is-horizontal {
  display: none;
}
.scrollbar :deep(.el-scrollbar__bar.is-horizontal){
  height: 0 !important;
}
.background{
  background-image: url("../../assets/answerbackground.png");
  background-size: 100% 100%;
  margin: 0;
  width: 100vw;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.background .big-contain{
  background-color: #f6f6f6;
  width: 60%;
  height: 92vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.buttonbar{
  height: 8vh;
  background-color: #f6f6f6;
  width: 60%;
  display: flex;
  flex-direction: row;
  align-content: space-around;
  justify-content: space-evenly;
}
.survey{
  background: #f6f6f6;
  border: #7c7c7c;
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  font-size: medium;
}

</style>
